/**
 * 转换时间日期
 * @param date
 * @returns {String}
 */
function transdate(date)
{
	var chardate=Array("年","月","日");
	var tmpdate=date.split("-");
	var returndate="";
	for(i=0;i<tmpdate.length;i++)
	{
		returndate+=tmpdate[i]+chardate[i];
	}
	return returndate;
}

/**
 * 验证是否输入
 */
function wtvali()
{
	var flag=true;
	if($("input[name='xccpzh']").val()=='')
	{
		$("input[name='xccpzh']").next().fadeIn('fast');
		flag=false;
	}
	if($("input[name='ccbfRq']").val()=='')
	{
		$("input[name='ccbfRq']").next().fadeIn('fast');
		flag=false;
	}
	return flag;
}
/**
 * 把信息代入要打印的模版中
 */
function parseIn()
{
	$("span.gzdXh").text($("input[name='gzdXh']").val());
	$("span.ccpzh").text($("input[name='ccpzh']").val());
	$("span.czMc").text($("input[name='czMc']").val());
	$("span.djRq").text(transdate($("input[name='djRq']").val()));
	$("span.cjh").text($("input[name='cjh']").val());
	$("span.fdjh").text($("input[name='fdjh']").val());
	$("span.ccbfRq").text(transdate($("input[name='ccbfRq']").val()));
	$("span.sbqsny").text(transdate($("input[name='sbqsny']").val())+"01月");
	$("span.czDh").text($("input[name='czDh']").val());
	$("span.xccpzh").text("粤T."+$("input[name='xccpzh']").val());
	$("span.cjRq").text(transdate($("input[name='cjRq']").val()));
	
}
//打印
function print(data)
{
	$('div.PrintArea').printArea({mode: "popup",popClose: true});
}
/**
 * 按下了“保存并打印”按钮
 */
function ShowPrint()
{
	if(wtvali())
	{
		
		$.blockUI({ message: $('div.PrintAreaPre'),
			css: { top:  ($(window).height() - 500) /2 + 'px', 
            left: ($(window).width() - 780) /2 + 'px', width: '780px',height: '500px',overflow: 'auto' } });
		parseIn();
	}
	else
		return false;
	
}
/**
 * 显示是否打印成功的信息
 */
function ShowMessage()
{
	$.unblockUI();
	$.blockUI({ 
        message: '<div><p>是否打印成功？</p><p><input type="button" value="打印成功" onclick="SubmitFunc()"/><input type="button" value="重新打印" onclick="print();"/></p>', 
        css: { border: '3px solid #a00' } 
    });
	print();
}
/**
 * 打印成功，提交
 */
function SubmitFunc()
{
	if($("input[name='cancel']").val()=="cancel")
	{
		$.unblockUI();
	}
	else
	{
		$("#form1").submit();
	}
}
